package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.UUID;

import oracle.net.aso.i;
import pojo.Order;
import util.DBUtil;
import dao.OrderDao;

public class OrderDaoImpl implements OrderDao {

	@Override
	public int addOrder(Order order) {
		String sql="insert into o_info (id,u_id,b_id,num,buy_time) values (?,?,?,?,?)";
		Connection connection = null;
		PreparedStatement pst=null;
		int m=0;
		try {
			connection = DBUtil.createConnection();
			pst = connection.prepareStatement(sql);
			pst.setString(1, order.getId());
			pst.setString(2, order.getUid());
			pst.setString(3, order.getBid());
			pst.setInt(4, order.getNum());
			pst.setDate(5, new java.sql.Date(order.getBuyTime().getTime()));
			m=pst.executeUpdate();
			return 1;
		} catch (SQLException e) {
			e.printStackTrace();
			return 0;
		} finally{
			DBUtil.close(connection, pst, null);
		}
	}

	@Override
	public int deleteOrder(String id) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateOrder(Order order) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Order getOrder(String id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<Order> findAll() {
		// TODO Auto-generated method stub
		return null;
	}
	
	public static void main(String[] args) {
		UUID id = UUID.randomUUID();
		System.out.println(id);
	}

}
